home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / SoundPlayerClass.java < prev    next >
Text File  |  1998-11-05  |  6KB  |  206 lines

  1. /*
  2.     A basic extension of the java.awt.Frame class
  3.  */
  4.  
  5. import java.awt.*;
  6. import symantec.itools.awt.ImageButton;
  7. import symantec.itools.multimedia.SoundPlayer;
  8. import symantec.itools.multimedia.ImageViewer;
  9.  
  10. public class SoundPlayerClass extends Frame
  11. {
  12.     public SoundPlayerClass()
  13.     {
  14.         // This code is automatically generated by Visual Cafe when you add
  15.         // components to the visual environment. It instantiates and initializes
  16.         // the components. To modify the code, only use code syntax that matches
  17.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  18.         // parse your Java file into its visual environment.
  19.         //{{INIT_CONTROLS
  20.         setLayout(null);
  21.         setBackground(java.awt.Color.lightGray);
  22.         setSize(400,300);
  23.         setVisible(false);
  24.         try {
  25.             imageButton2.setImageURL(symantec.itools.net.RelativeURL.getURL("images/play.gif"));
  26.         }
  27.         catch (java.net.MalformedURLException error) { }
  28.         catch(java.beans.PropertyVetoException e) { }
  29.         add(imageButton2);
  30.         imageButton2.setBounds(240,145,57,58);
  31.         try {
  32.             imageButton1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/stop.gif"));
  33.         }
  34.         catch (java.net.MalformedURLException error) { }
  35.         catch(java.beans.PropertyVetoException e) { }
  36.         add(imageButton1);
  37.         imageButton1.setBounds(136,145,57,58);
  38.         try {
  39.             imageViewer1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/right.gif"));
  40.         }
  41.         catch (java.net.MalformedURLException error) { }
  42.         catch(java.beans.PropertyVetoException e) { }
  43.         add(imageViewer1);
  44.         imageViewer1.setBounds(42,7,136,131);
  45.         try {
  46.             java.net.URL[] tempURL = new java.net.URL[5];
  47.             tempURL[0] = symantec.itools.net.RelativeURL.getURL("sounds/T1.au");
  48.             tempURL[1] = symantec.itools.net.RelativeURL.getURL("sounds/T2.au");
  49.             tempURL[2] = symantec.itools.net.RelativeURL.getURL("sounds/T3.au");
  50.             tempURL[3] = symantec.itools.net.RelativeURL.getURL("sounds/T4.au");
  51.             tempURL[4] = symantec.itools.net.RelativeURL.getURL("sounds/T5.au");
  52.             soundPlayer1.setURLList(tempURL);
  53.         }
  54.         catch (java.net.MalformedURLException error) { }
  55.         catch(java.beans.PropertyVetoException e) { }
  56.         //$$ soundPlayer1.move(212,61);
  57.         try {
  58.             imageViewer2.setImageURL(symantec.itools.net.RelativeURL.getURL("images/right.gif"));
  59.         }
  60.         catch (java.net.MalformedURLException error) { }
  61.         catch(java.beans.PropertyVetoException e) { }
  62.         add(imageViewer2);
  63.         imageViewer2.setBounds(251,7,136,131);
  64.         setTitle("A Simple Frame");
  65.         //}}
  66.  
  67.         //{{INIT_MENUS
  68.         //}}
  69.  
  70.         //{{REGISTER_LISTENERS
  71.         SymWindow aSymWindow = new SymWindow();
  72.         this.addWindowListener(aSymWindow);
  73.         SymAction lSymAction = new SymAction();
  74.         imageButton2.addActionListener(lSymAction);
  75.         imageButton1.addActionListener(lSymAction);
  76.         //}}
  77.     }
  78.  
  79.     public SoundPlayerClass(String title)
  80.     {
  81.         this();
  82.         setTitle(title);
  83.     }
  84.  
  85.     /**
  86.      * Shows or hides the component depending on the boolean flag b.
  87.      * @param b  if true, show the component; otherwise, hide the component.
  88.      * @see java.awt.Component#isVisible
  89.      */
  90.     public void setVisible(boolean b)
  91.     {
  92.         if(b)
  93.         {
  94.             setLocation(50, 50);
  95.         }
  96.         super.setVisible(b);
  97.     }
  98.  
  99.     static public void main(String args[])
  100.     {
  101.         (new SoundPlayerClass()).setVisible(true);
  102.     }
  103.     
  104.     public void addNotify()
  105.     {
  106.         // Record the size of the window prior to calling parents addNotify.
  107.         Dimension d = getSize();
  108.         
  109.         super.addNotify();
  110.  
  111.         if (fComponentsAdjusted)
  112.             return;
  113.  
  114.         // Adjust components according to the insets
  115.         Insets insets = getInsets();
  116.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  117.         Component components[] = getComponents();
  118.         for (int i = 0; i < components.length; i++)
  119.         {
  120.             Point p = components[i].getLocation();
  121.             p.translate(insets.left, insets.top);
  122.             components[i].setLocation(p);
  123.         }
  124.         fComponentsAdjusted = true;
  125.     }
  126.  
  127.     // Used for addNotify check.
  128.     boolean fComponentsAdjusted = false;
  129.  
  130.     //{{DECLARE_CONTROLS
  131.     symantec.itools.awt.ImageButton imageButton2 = new symantec.itools.awt.ImageButton();
  132.     symantec.itools.awt.ImageButton imageButton1 = new symantec.itools.awt.ImageButton();
  133.     symantec.itools.multimedia.ImageViewer imageViewer1 = new symantec.itools.multimedia.ImageViewer();
  134.     symantec.itools.multimedia.SoundPlayer soundPlayer1 = new symantec.itools.multimedia.SoundPlayer();
  135.     symantec.itools.multimedia.ImageViewer imageViewer2 = new symantec.itools.multimedia.ImageViewer();
  136.     //}}
  137.  
  138.     //{{DECLARE_MENUS
  139.     //}}
  140.  
  141.     class SymWindow extends java.awt.event.WindowAdapter
  142.     {
  143.         public void windowClosing(java.awt.event.WindowEvent event)
  144.         {
  145.             Object object = event.getSource();
  146.             if (object == SoundPlayerClass.this)
  147.                 SoundPlayerClass_WindowClosing(event);
  148.         }
  149.     }
  150.     
  151.     void SoundPlayerClass_WindowClosing(java.awt.event.WindowEvent event)
  152.     {
  153.         setVisible(false);         // hide the Frame
  154.         
  155.         try {
  156.             // soundPlayer1 Stop the sound player
  157.             soundPlayer1.stop();
  158.         } catch (Exception e) {
  159.         }
  160.     }
  161.  
  162.     class SymAction implements java.awt.event.ActionListener
  163.     {
  164.         public void actionPerformed(java.awt.event.ActionEvent event)
  165.         {
  166.             Object object = event.getSource();
  167.             if (object == imageButton2)
  168.                 imageButton2_actionPerformed(event);
  169.             else if (object == imageButton1)
  170.                 imageButton1_actionPerformed(event);
  171.         }
  172.     }
  173.  
  174.     void imageButton2_actionPerformed(java.awt.event.ActionEvent event)
  175.     {
  176.         // to do: code goes here.
  177.              
  178.         imageButton2_actionPerformed_Interaction1(event);
  179.     }
  180.  
  181.     void imageButton2_actionPerformed_Interaction1(java.awt.event.ActionEvent event)
  182.     {
  183.         try {
  184.             // soundPlayer1 Start the sound player
  185.             soundPlayer1.play();
  186.         } catch (Exception e) {
  187.         }
  188.     }
  189.  
  190.     void imageButton1_actionPerformed(java.awt.event.ActionEvent event)
  191.     {
  192.         // to do: code goes here.
  193.              
  194.         imageButton1_actionPerformed_Interaction1(event);
  195.     }
  196.  
  197.     void imageButton1_actionPerformed_Interaction1(java.awt.event.ActionEvent event)
  198.     {
  199.         try {
  200.             // soundPlayer1 Stop the sound player
  201.             soundPlayer1.stop();
  202.         } catch (Exception e) {
  203.         }
  204.     }
  205. }
  206.